package com.bxl.netty.rpc.client;


import com.bxl.netty.rpc.client.proxy.RpcProxy;
import com.bxl.rpc.api.IHello;
import com.bxl.rpc.api.IService;
import com.bxl.rpc.api.entity.Person;

/**
 * <>
 *
 * @author baixl
 * @date 2021/2/24
 */
public class Consumer {
    public static void main(String[] args) {
        for (int j = 0; j < 10; j++) {
            Thread t = new Thread(
                    new Runnable() {
                        public void run() {
                            String str = "IHello!";
                            // 发送1000000条消息
                            for (int i = 0; i < 10000; i++) {
                                String content = str + "----" + i;
                                long start =System.currentTimeMillis();
                                System.out.println("content="+content+";response::"+ RpcProxy.proxyGet(IHello.class).say(content));
                                System.out.println("IHello use time:"+(System.currentTimeMillis()-start));
                            }
                        }
                    }
            );
            t.start();

            Thread t1 = new Thread(
                    new Runnable() {
                        public void run() {
                            String str = "IService!";
                            // 发送1000000条消息
                            IService service = RpcProxy.proxyGet(IService.class);
                            for (int i = 0; i < 100000; i++) {
                                String content = str + "----" + i;
                                //客户端也可以采用过滤器的模式，对发送消息进行扩展处理
                                long start =System.currentTimeMillis();
                                Person person = service.getPerson(content,"Gril");
                                System.out.println("person use time:"+(System.currentTimeMillis()-start));
                                System.out.println("content="+content+";response::"+person);
                            }
                        }
                    }
            );
            t1.start();
        }


    }
}
